import instance from './index';
import qs from 'qs';

const preUrlPath = '';
//获取角色列表-分页
const request = {
  p: ['api:role:fetch'],
  r: params => {
    return instance.get(`/role/fetchPageList`, {params})
  }
};
//获取角色列表-不分页
const requestList = {
  p: ['api:role:fetch'],
  r: params => {
    return instance.get(`/role/fetchRoleList`, {params})
  }
};
//添加角色
const add = {
  p: ['api:role:new'],
  r: params => {
    return instance.post(`/role/new`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//获取角色信息
const info = {
  p: ['api:role:fetch'],
  r: params => {
    return instance.get(`/role/info`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//获取用户信息
const userinfo = {
  p: ['api:role:fetch'],
  r: params => {
    return instance.get(`/user/info`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//编辑角色
const modify = {
  p: ['api:role:modify'],
  r: params => {
    return instance.post(`/role/modify`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//删除角色
const remove = {
  p: ['api:role:delete'],
  r: params => {
    // return instance.get(`${preUrlPath}/role/${params.id}`)
    return instance.delete(`/role/del/${params.id}`)

  }
};
//关联角色-用户关联
const relerole = {
  p: ['api:user:addRoleRlt'],
  r: params => {
    return instance.post(`/user/addRoleRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联角色--用户组
const releroleGroup = {
  p: ['api:group:addRoleRlt'],
  r: params => {
    return instance.post(`/group/addRoleRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联角色--权限关联
const releroleAuth = {
  p: ['api:group:addRoleRlt'],
  r: params => {
    return instance.post(`/permission/addRoleRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联用户-角色关联
const releUser = {
  p: ['api:role:addUserRlt'],
 
};
//关联分组-角色关联
const releGroupRole = {
  p: ['api:role:addGroupRlt'],
 
};
//添加权限-角色关联
const addAuthRole = {
  p: ['api:role:addPermissionRlt'],
 
};
//越权请求
const notAllowed = {
  p: ['get,/roles/notAllowed'],
  r: params => {
    return instance.get(`${preUrlPath}/GET/roles/notAllowed`, {params})
  }
}

export {
  request,
  remove,
  notAllowed,
  add,
  modify,
  info,
  userinfo,
  relerole,
  requestList,
  releroleGroup,
  releroleAuth,
  releUser,
  releGroupRole,
  addAuthRole
}
